package org.game.db.bean;

import org.game.db.cache.RoleCache;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Date;
import static org.game.db.StaticResource.RoleResource.*;
import org.apache.commons.lang3.ArrayUtils;
import org.game.db.cache.ReserveDateRecordCache;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.util.List;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import org.cfg.cache.RoleCfgCache;
import org.game.db.cache.PlayerCache;
import java.sql.ResultSet;
import java.util.Map;
import org.apache.commons.lang3.builder.ToStringBuilder;
import com.alibaba.fastjson.JSONObject;
import org.game.db.vo.DressVO;
import org.game.quartz.QuartzUpdater;
import org.cfg.RoleCfg;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.game.db.StaticResource.RoleResource.*;
/**
 * 精灵(板娘)
 */
public class Role extends BasePojo<Role> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[3];
	
	/**
	* id
	*/
	private long id;
	
	/**
	* 配置ID
	*/
	private int cid;
	
	/**
	* 玩家ID
	*/
	private int playerId;
	
	/**
	* 好感度经验值
	*/
	private int favor;
	
	/**
	* 心情值
	*/
	private int mood;
	
	/**
	* 精灵状态(0：为使用 1：使用)
	*/
	private int status;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 解锁礼品
	*/
	private List unlockGift;
	
	/**
	* 解锁爱好
	*/
	private List unlockHobby;
	
	/**
	* 时装约会
	*/
	private List dressDating;
	
	/**
	* 赠送礼物约会
	*/
	private Map donateDating;
	
	/**
	* 上次心情值刷新时间
	*/
	private java.util.Date lastMoodUpdateTime;
	
	/**
	* 打工建筑id，没有打工则是0
	*/
	private int workBuildingId;
	
	/**
	* 好感度临界点，true则不能继续提升好感度
	*/
	private boolean criticalPoint;
	
	/**
	* 触发约会
	*/
	private List triggerDating;
	
	/**
	* 当日城市约会次数
	*/
	private int todayCityDatingCount;
	
	/**
	* 上次刷新时间
	*/
	private java.util.Date lastRefreshTime;
	
	
	@Deprecated
	public static Role builder() {
		Role role = new Role();
		return role;
	}
	
	@Deprecated
	public Role() {
		super();
	}
	
	public Role(long id, int cid, int playerId, int favor, int mood, int status, List unlockGift, List unlockHobby, List dressDating, Map donateDating, java.util.Date lastMoodUpdateTime, int workBuildingId, boolean criticalPoint, List triggerDating, int todayCityDatingCount, java.util.Date lastRefreshTime) {
		super();
		this.id = id;
		this.cid = cid;
		this.playerId = playerId;
		this.favor = favor;
		this.mood = mood;
		this.status = status;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.unlockGift = unlockGift;
		this.unlockHobby = unlockHobby;
		this.dressDating = dressDating;
		this.donateDating = donateDating;
		this.lastMoodUpdateTime = lastMoodUpdateTime;
		this.workBuildingId = workBuildingId;
		this.criticalPoint = criticalPoint;
		this.triggerDating = triggerDating;
		this.todayCityDatingCount = todayCityDatingCount;
		this.lastRefreshTime = lastRefreshTime;
	}
	
	/**
	 * id
	 */
	public long getId() {return id;}
	
	/**
	 * id
	 */
	public Role setId(long id) {this.id = id;return this;}
	
	/**
	 * 配置ID
	 */
	public int getCid() {return cid;}
	
	/**
	 * 配置ID
	 */
	public Role setCid(int cid) {this.cid = cid;return this;}
	
	/**
	 * 玩家ID
	 */
	public int getPlayerId() {return playerId;}
	
	/**
	 * 玩家ID
	 */
	public Role setPlayerId(int playerId) {this.playerId = playerId;return this;}
	
	/**
	 * 好感度经验值
	 */
	public int getFavor() {return favor;}
	
	/**
	 * 好感度经验值
	 */
	public Role setFavor(int favor) {this.favor = favor;return this;}
	
	/**
	 * 心情值
	 */
	public int getMood() {return mood;}
	
	/**
	 * 心情值
	 */
	public Role setMood(int mood) {this.mood = mood;return this;}
	
	/**
	 * 精灵状态(0：为使用 1：使用)
	 */
	public int getStatus() {return status;}
	
	/**
	 * 精灵状态(0：为使用 1：使用)
	 */
	public Role setStatus(int status) {this.status = status;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected Role setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected Role setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 解锁礼品
	 */
	public List getUnlockGift() {return unlockGift;}
	
	/**
	 * 解锁礼品
	 */
	public Role setUnlockGift(List unlockGift) {this.unlockGift = unlockGift;return this;}
	
	/**
	 * 解锁礼品
	 */
	public byte[] getUnlockGiftByte() {
		return toBytes(unlockGift);
	}
	
	/**
	 * 解锁礼品
	 */
	public List initUnlockGiftByte(byte[] _byte) {
		return (List)forBytesObject(_byte);
	}	
	/**
	 * 解锁爱好
	 */
	public List getUnlockHobby() {return unlockHobby;}
	
	/**
	 * 解锁爱好
	 */
	public Role setUnlockHobby(List unlockHobby) {this.unlockHobby = unlockHobby;return this;}
	
	/**
	 * 解锁爱好
	 */
	public byte[] getUnlockHobbyByte() {
		return toBytes(unlockHobby);
	}
	
	/**
	 * 解锁爱好
	 */
	public List initUnlockHobbyByte(byte[] _byte) {
		return (List)forBytesObject(_byte);
	}	
	/**
	 * 时装约会
	 */
	public List getDressDating() {return dressDating;}
	
	/**
	 * 时装约会
	 */
	public Role setDressDating(List dressDating) {this.dressDating = dressDating;return this;}
	
	/**
	 * 时装约会
	 */
	public byte[] getDressDatingByte() {
		return toBytes(dressDating);
	}
	
	/**
	 * 时装约会
	 */
	public List initDressDatingByte(byte[] _byte) {
		return (List)forBytesObject(_byte);
	}	
	/**
	 * 赠送礼物约会
	 */
	public Map getDonateDating() {return donateDating;}
	
	/**
	 * 赠送礼物约会
	 */
	public Role setDonateDating(Map donateDating) {this.donateDating = donateDating;return this;}
	
	/**
	 * 赠送礼物约会
	 */
	public byte[] getDonateDatingByte() {
		return toBytes(donateDating);
	}
	
	/**
	 * 赠送礼物约会
	 */
	public Map initDonateDatingByte(byte[] _byte) {
		return (Map)forBytesObject(_byte);
	}	
	/**
	 * 上次心情值刷新时间
	 */
	public java.util.Date getLastMoodUpdateTime() {return lastMoodUpdateTime;}
	
	/**
	 * 上次心情值刷新时间
	 */
	public Role setLastMoodUpdateTime(java.util.Date lastMoodUpdateTime) {this.lastMoodUpdateTime = lastMoodUpdateTime;return this;}
	
	/**
	 * 打工建筑id，没有打工则是0
	 */
	public int getWorkBuildingId() {return workBuildingId;}
	
	/**
	 * 打工建筑id，没有打工则是0
	 */
	public Role setWorkBuildingId(int workBuildingId) {this.workBuildingId = workBuildingId;return this;}
	
	/**
	 * 好感度临界点，true则不能继续提升好感度
	 */
	public boolean isCriticalPoint() {return criticalPoint;}
	
	/**
	 * 好感度临界点，true则不能继续提升好感度
	 */
	public Role setCriticalPoint(boolean criticalPoint) {this.criticalPoint = criticalPoint;return this;}
	
	/**
	 * 触发约会
	 */
	public List getTriggerDating() {return triggerDating;}
	
	/**
	 * 触发约会
	 */
	public Role setTriggerDating(List triggerDating) {this.triggerDating = triggerDating;return this;}
	
	/**
	 * 触发约会
	 */
	public byte[] getTriggerDatingByte() {
		return toBytes(triggerDating);
	}
	
	/**
	 * 触发约会
	 */
	public List initTriggerDatingByte(byte[] _byte) {
		return (List)forBytesObject(_byte);
	}	
	/**
	 * 当日城市约会次数
	 */
	public int getTodayCityDatingCount() {return todayCityDatingCount;}
	
	/**
	 * 当日城市约会次数
	 */
	public Role setTodayCityDatingCount(int todayCityDatingCount) {this.todayCityDatingCount = todayCityDatingCount;return this;}
	
	/**
	 * 上次刷新时间
	 */
	public java.util.Date getLastRefreshTime() {return lastRefreshTime;}
	
	/**
	 * 上次刷新时间
	 */
	public Role setLastRefreshTime(java.util.Date lastRefreshTime) {this.lastRefreshTime = lastRefreshTime;return this;}
	
	
	// 代理
	private org.game.db.proxy.bean.RoleProxy roleProxy = new org.game.db.proxy.bean.RoleProxy().build(this);
	
	public org.game.db.proxy.bean.RoleProxy getRoleProxy(){return roleProxy;}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.cid;
        values[2] = this.playerId;
        values[3] = this.favor;
        values[4] = this.mood;
        values[5] = this.status;
        values[6] = this.createDate;
        values[7] = this.modifiedDate;
        values[8] = this.unlockGift;
        values[9] = this.unlockHobby;
        values[10] = this.dressDating;
        values[11] = this.donateDating;
        values[12] = this.lastMoodUpdateTime;
        values[13] = this.workBuildingId;
        values[14] = this.criticalPoint;
        values[15] = this.triggerDating;
        values[16] = this.todayCityDatingCount;
        values[17] = this.lastRefreshTime;
        return values;
	}
	
	public Role deepCopy(){
		Role role = null;
		try {
			role = (Role) super.clone();
		    role.setCreateDate(ToolCopy.copyObject(this.createDate));
		    role.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    role.setUnlockGift(ToolCopy.copyObject(this.unlockGift));
		    role.setUnlockHobby(ToolCopy.copyObject(this.unlockHobby));
		    role.setDressDating(ToolCopy.copyObject(this.dressDating));
		    role.setDonateDating(ToolCopy.copyObject(this.donateDating));
		    role.setLastMoodUpdateTime(ToolCopy.copyObject(this.lastMoodUpdateTime));
		    role.setTriggerDating(ToolCopy.copyObject(this.triggerDating));
		    role.setLastRefreshTime(ToolCopy.copyObject(this.lastRefreshTime));
		    // 克隆索引
		    role.indexValues = ArrayUtils.clone(indexValues);
			return role;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return role;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.cid);
        map.put(keys[2], this.playerId);
        map.put(keys[3], this.favor);
        map.put(keys[4], this.mood);
        map.put(keys[5], this.status);
        map.put(keys[6], this.createDate);
        map.put(keys[7], this.modifiedDate);
        map.put(keys[8], this.unlockGift);
        map.put(keys[9], this.unlockHobby);
        map.put(keys[10], this.dressDating);
        map.put(keys[11], this.donateDating);
        map.put(keys[12], this.lastMoodUpdateTime);
        map.put(keys[13], this.workBuildingId);
        map.put(keys[14], this.criticalPoint);
        map.put(keys[15], this.triggerDating);
        map.put(keys[16], this.todayCityDatingCount);
        map.put(keys[17], this.lastRefreshTime);
        return map;
    }
    
    protected Role createForMap(Object[] keys,Map map){
   		this.id = (long)map.get(keys[0]);
   		this.cid = (int)map.get(keys[1]);
   		this.playerId = (int)map.get(keys[2]);
   		this.favor = (int)map.get(keys[3]);
   		this.mood = (int)map.get(keys[4]);
   		this.status = (int)map.get(keys[5]);
   		this.createDate = (java.util.Date)map.get(keys[6]);
   		this.modifiedDate = (java.util.Date)map.get(keys[7]);
   		this.unlockGift = (List)map.get(keys[8]);
   		this.unlockHobby = (List)map.get(keys[9]);
   		this.dressDating = (List)map.get(keys[10]);
   		this.donateDating = (Map)map.get(keys[11]);
   		this.lastMoodUpdateTime = (java.util.Date)map.get(keys[12]);
   		this.workBuildingId = (int)map.get(keys[13]);
   		this.criticalPoint = (boolean)map.get(keys[14]);
   		this.triggerDating = (List)map.get(keys[15]);
   		this.todayCityDatingCount = (int)map.get(keys[16]);
   		this.lastRefreshTime = (java.util.Date)map.get(keys[17]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.cid);
        obj.put(keys[2], this.playerId);
        obj.put(keys[3], this.favor);
        obj.put(keys[4], this.mood);
        obj.put(keys[5], this.status);
        obj.put(keys[6], this.createDate);
        obj.put(keys[7], this.modifiedDate);
        obj.put(keys[8], toBytes(unlockGift));
        obj.put(keys[9], toBytes(unlockHobby));
        obj.put(keys[10], toBytes(dressDating));
        obj.put(keys[11], toBytes(donateDating));
        obj.put(keys[12], this.lastMoodUpdateTime);
        obj.put(keys[13], this.workBuildingId);
        obj.put(keys[14], this.criticalPoint);
        obj.put(keys[15], toBytes(triggerDating));
        obj.put(keys[16], this.todayCityDatingCount);
        obj.put(keys[17], this.lastRefreshTime);
        return obj;
    }
    
    protected Role createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getLongValue(keys[0]);
	    this.cid = obj.getIntValue(keys[1]);
	    this.playerId = obj.getIntValue(keys[2]);
	    this.favor = obj.getIntValue(keys[3]);
	    this.mood = obj.getIntValue(keys[4]);
	    this.status = obj.getIntValue(keys[5]);
	    this.createDate = obj.getDate(keys[6]);
	    this.modifiedDate = obj.getDate(keys[7]);
		this.unlockGift = (List)forBytesObject(obj.getBytes(keys[8]));
		this.unlockHobby = (List)forBytesObject(obj.getBytes(keys[9]));
		this.dressDating = (List)forBytesObject(obj.getBytes(keys[10]));
		this.donateDating = (Map)forBytesObject(obj.getBytes(keys[11]));
	    this.lastMoodUpdateTime = obj.getDate(keys[12]);
	    this.workBuildingId = obj.getIntValue(keys[13]);
	    this.criticalPoint = obj.getBooleanValue(keys[14]);
		this.triggerDating = (List)forBytesObject(obj.getBytes(keys[15]));
	    this.todayCityDatingCount = obj.getIntValue(keys[16]);
	    this.lastRefreshTime = obj.getDate(keys[17]);
        return this;
    }
    
    
    public Role createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getLong(SOURCE_COLUMN_NAMES[0]);
	    this.cid = rs.getInt(SOURCE_COLUMN_NAMES[1]);
	    this.playerId = rs.getInt(SOURCE_COLUMN_NAMES[2]);
	    this.favor = rs.getInt(SOURCE_COLUMN_NAMES[3]);
	    this.mood = rs.getInt(SOURCE_COLUMN_NAMES[4]);
	    this.status = rs.getInt(SOURCE_COLUMN_NAMES[5]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[6]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[7]);
		this.unlockGift = (List)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[8]));
		this.unlockHobby = (List)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[9]));
		this.dressDating = (List)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[10]));
		this.donateDating = (Map)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[11]));
	    this.lastMoodUpdateTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[12]);
	    this.workBuildingId = rs.getInt(SOURCE_COLUMN_NAMES[13]);
	    this.criticalPoint = rs.getBoolean(SOURCE_COLUMN_NAMES[14]);
		this.triggerDating = (List)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[15]));
	    this.todayCityDatingCount = rs.getInt(SOURCE_COLUMN_NAMES[16]);
	    this.lastRefreshTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[17]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeLong(this.id);
	    byteBuf.writeInt(this.cid);
	    byteBuf.writeInt(this.playerId);
	    byteBuf.writeInt(this.favor);
	    byteBuf.writeInt(this.mood);
	    byteBuf.writeInt(this.status);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeObject(this.unlockGift);
	    byteBuf.writeObject(this.unlockHobby);
	    byteBuf.writeObject(this.dressDating);
	    byteBuf.writeObject(this.donateDating);
	    byteBuf.writeDate(this.lastMoodUpdateTime);
	    byteBuf.writeInt(this.workBuildingId);
	    byteBuf.writeBoolean(this.criticalPoint);
	    byteBuf.writeObject(this.triggerDating);
	    byteBuf.writeInt(this.todayCityDatingCount);
	    byteBuf.writeDate(this.lastRefreshTime);
    }
	
	protected Role readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readLong(null);
	    this.cid = byteBuf.readInt(null);
	    this.playerId = byteBuf.readInt(null);
	    this.favor = byteBuf.readInt(null);
	    this.mood = byteBuf.readInt(null);
	    this.status = byteBuf.readInt(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.unlockGift = (List)byteBuf.readObject();
	    this.unlockHobby = (List)byteBuf.readObject();
	    this.dressDating = (List)byteBuf.readObject();
	    this.donateDating = (Map)byteBuf.readObject();
	    this.lastMoodUpdateTime = byteBuf.readDate(null);
	    this.workBuildingId = byteBuf.readInt(null);
	    this.criticalPoint = byteBuf.readBoolean(null);
	    this.triggerDating = (List)byteBuf.readObject();
	    this.todayCityDatingCount = byteBuf.readInt(null);
	    this.lastRefreshTime = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		// reserve_date_record
		map.put(keys[0],exprotHelp(this.getReserveDateRecordsFkRoleId(),e));
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		// reserve_date_record
		improtHelp(map.getJSONObject(keys[0]),ReserveDateRecord.builder(),e,0,this.getId());
		return true;
    }
    
	/** 取得[reserve_date_record] */
	public ReserveDateRecord getReserveDateRecordsFkRoleId(){
		return ReserveDateRecordCache.me().getByRoleId(id);
	}
	
	/** 取得[player]*/
	public Player getPlayerPkPlayerId(){
		return PlayerCache.me().getById(playerId);
	}
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public Role insert(){
    	return RoleCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public Role update(){
    	return RoleCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return RoleCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public Role insertAndFlush(){
    	return RoleCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Role updateAndFlush(){
    	return RoleCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return RoleCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public Role syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getCid(),"_",getPlayerId()).e();
		indexValues[2] = SK_Plus.b(getPlayerId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((long)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}